#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h> 
#include <stdlib.h>
#include <assert.h>
#include "app_platform/cntl_info.h"
#include "cooperatordao.h"
#include "c2cplatform/library/the3/itil/c2c_attr.h"

#include "b2b2c_define.h"
#include "c2cent/storage/mysqlstorage.h" //mysql Storage
#include "b2b2c/library/tmem_client_new.h"
#include "library/algorithm/algorithm.h"
#include "app_platform/db_operator2.h"
#include "cooperatordao_enum.h"

using namespace c2cent::library::wwlog;
using namespace c2cent::library::wtimeelf;
using namespace c2cent::storage;
using namespace b2b2c::comm;
using namespace b2b2c::comm::tmem;
using namespace c2cplatform::library::algorithm;

using namespace b2b2c::cooperator::dao;
using namespace item::cooperator::db;

CCooperatorDBOperator CCooperatorDao::m_oDBOperator;

CItilGroup CCooperatorDao::m_oUpdateCooperatorBaseInfoGroup(ITIL_COOPERATOR_BASEINFO_UPDATE_REQ,ITIL_COOPERATOR_BASEINFO_UPDATE_ERR,ITIL_COOPERATOR_BASEINFO_UPDATE_RSP,ITIL_COOPERATOR_BASEINFO_UPDATE_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oGetCooperatorLicenseGroup(ITIL_COOPERATOR_LICENSE_GET_REQ,ITIL_COOPERATOR_LICENSE_GET_ERR,ITIL_COOPERATOR_LICENSE_GET_RSP,ITIL_COOPERATOR_LICENSE_GET_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oGetCooperatorBaseInfoGroup(ITIL_COOPERATOR_BASEINFO_GET_REQ,ITIL_COOPERATOR_BASEINFO_GET_ERR,ITIL_COOPERATOR_BASEINFO_GET_RSP,ITIL_COOPERATOR_BASEINFO_GET_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oSetCooperatorPassWdGroup(ITIL_COOPERATOR_PASSWD_SET_REQ,ITIL_COOPERATOR_PASSWD_SET_ERR,ITIL_COOPERATOR_PASSWD_SET_RSP,ITIL_COOPERATOR_PASSWD_SET_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oCheckCooperatorPassWdGroup(ITIL_COOPERATOR_PASSWD_CHECK_REQ,ITIL_COOPERATOR_PASSWD_CHECK_ERR,ITIL_COOPERATOR_PASSWD_CHECK_RSP,ITIL_COOPERATOR_PASSWD_CHECK_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oUpdateCooperatorLicenseGroup(ITIL_COOPERATOR_LICENSE_UPDATE_REQ,ITIL_COOPERATOR_LICENSE_UPDATE_ERR,ITIL_COOPERATOR_LICENSE_UPDATE_RSP,ITIL_COOPERATOR_LICENSE_UPDATE_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oGetCooperatorKeyGroup(ITIL_COOPERATOR_GET_KEY_REQ,ITIL_COOPERATOR_GET_KEY_ERR,ITIL_COOPERATOR_GET_KEY_RSP,ITIL_COOPERATOR_GET_KEY_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oLogisticsSetCooperatorPro(ITIL_LOGISTICS_SET_COOPERATOR_PRO_REQ,ITIL_LOGISTICS_SET_COOPERATOR_PRO_ERR,ITIL_LOGISTICS_SET_COOPERATOR_PRO_RSP,ITIL_LOGISTICS_SET_COOPERATOR_PRO_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oSetCooperatorInfo(ITIL_SET_COOPERATOR_INFO_REQ,ITIL_SET_COOPERATOR_INFO_ERR,ITIL_SET_COOPERATOR_INFO_RSP,ITIL_SET_COOPERATOR_INFO_DEF,TIME_50MS);

CItilGroup CCooperatorDao::m_oGetMonitorModelListGroup(ITIL_MINITOR_GET_MODELLIST_REQ,ITIL_MINITOR_GET_MODELLIST_ERR,ITIL_MINITOR_GET_MODELLIST_RSP,ITIL_MINITOR_GET_MODELLIST_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oGetMonitorModelGroup(ITIL_MINITOR_GET_MODEL_REQ,ITIL_MINITOR_GET_MODEL_ERR,ITIL_MINITOR_GET_MODEL_RSP,ITIL_MINITOR_GET_MODEL_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oUpdateMonitorModelGroup(ITIL_MINITOR_UPDATE_MODEL_REQ,ITIL_MINITOR_UPDATE_MODEL_ERR,ITIL_MINITOR_UPDATE_MODEL_RSP,ITIL_MINITOR_UPDATE_MODEL_DEF,TIME_50MS);
CItilGroup CCooperatorDao::m_oDeleteMonitorModelGroup(ITIL_MINITOR_DEL_MODEL_REQ,ITIL_MINITOR_DEL_MODEL_ERR,ITIL_MINITOR_DEL_MODEL_RSP,ITIL_MINITOR_DEL_MODEL_DEF,TIME_50MS);

#define COOPERATOR_TMEMCACHE_DEF_EXPIRE_TIME  90*3600*24
#define COOPERATOR_CMEM_PREFIX "Cooperator_"
#define COOPERATOR_KEY_CMEM_PREFIX "CooperatorKey_"
#define COOPERATOR_MONITOR_CMEM_PREFIX "CooperatorMonitor_"

/**
 *构建函数
 */
CCooperatorDao::CCooperatorDao(enum DeployMethod method)
{


}

/**
 *析构函数
 */
CCooperatorDao::~CCooperatorDao()
{
}

/**
 *每一次服务请求时，container都会调用此方法来清空数据
 */
void  CCooperatorDao::Reset()
{
    m_dwOperatorUin=0;
    m_dwSceneId=0;
    m_strMachineKey="";
    m_strSource="";
}

int32_t CCooperatorDao::InitTMEM(IUserDefineCntl* pCntl){
    int32_t iRetCode = 0;
    std::string strTmemSvrName ="Cooperator_Tmem_Acc";
    uint32_t dwTmemBid = 102030068;
    std::map<TmemCacheItilEnum, uint32_t> mapTmemItil;
    uint64_t dwTmemExpireTime = COOPERATOR_TMEMCACHE_DEF_EXPIRE_TIME;
    uint32_t dwTmemReadSlowTime = TMEMCACHE_DEF_SLOW_TIME;
    uint32_t dwTmemBatchReadSlowTime = TMEMCACHE_DEF_SLOW_TIME;
    uint32_t dwTmemWriteSlowTime = TMEMCACHE_DEF_SLOW_TIME;
    uint32_t dwTmemBufferSize = TMEMCACHE_BUFFER_SIZE;
    uint32_t dwTmemUpdateAddrThreshold = TMEMCACHE_UPDATEADDR_THREDHOLD;
    bool bTmemUserNoKey = true;
    bool bTmemClosedCache = false;
    uint32_t dwTmemReadTimeout = TMEMCACHE_READ_TIMEOUT;
    uint32_t dwTmemFailedFreezeTime = TMEMCACHE_FAILED_FREEZE_TIME;
    uint32_t dwTmemConnectTimeout = TMEMCACHE_CONNECT_TIMEOUT;

    GetStringConfig(TmemSvrName);
    GetUintConfig(TmemBid);
    GetUintConfig(TmemExpireTime);
    GetUintConfig(TmemReadSlowTime);
    GetUintConfig(TmemBatchReadSlowTime);
    GetUintConfig(TmemWriteSlowTime);
    GetUintConfig(TmemBufferSize);
    GetUintConfig(TmemUpdateAddrThreshold);

    uint32_t dwTmemUserNoKey = 1;
    GetUintConfig(TmemUserNoKey);
    if(dwTmemUserNoKey != 0)
    {
        bTmemUserNoKey = true;
    }
    else
    {
        bTmemUserNoKey = false;
    }

    uint32_t dwTmemClosedCache = 0;
    GetUintConfig(TmemClosedCache);
    if(dwTmemClosedCache != 0)
    {
        bTmemClosedCache = true;
    }
    else
    {
        bTmemClosedCache = false;
    }

    GetUintConfig(TmemReadTimeout);
    GetUintConfig(TmemFailedFreezeTime);
    GetUintConfig(TmemConnectTimeout);

    uint32_t dwTmemWriteSlowItil = 617312;
    uint32_t dwTmemReadSlowItil = 617313;
    uint32_t dwTmemBatchReadSlowItil = 0;
    uint32_t dwTmemWriteErrorItil = 617314;
    uint32_t dwTmemReadErrorItil = 617315;
    uint32_t dwTmemBatchReadErrorItil = 0;
    uint32_t dwTmemWriteRequestItil = 617316;
    uint32_t dwTmemReadRequestItil = 617317;
    uint32_t dwTmemBatchReadRequestItil = 0;
    uint32_t dwTmemBatchReadCellRequestItil = 0;
    uint32_t dwTmemReadHitItil = 617318;
    uint32_t dwTmemBatchReadCellHitItil = 0;

    GetUintConfig(TmemWriteSlowItil);
    GetUintConfig(TmemReadSlowItil);
    GetUintConfig(TmemBatchReadSlowItil);
    GetUintConfig(TmemWriteErrorItil);
    GetUintConfig(TmemReadErrorItil);
    GetUintConfig(TmemBatchReadErrorItil);
    GetUintConfig(TmemWriteRequestItil);
    GetUintConfig(TmemReadRequestItil);
    GetUintConfig(TmemBatchReadRequestItil);
    GetUintConfig(TmemBatchReadCellRequestItil);
    GetUintConfig(TmemReadHitItil);
    GetUintConfig(TmemBatchReadCellHitItil);

    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_WRITE_SLOW,  dwTmemWriteSlowItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_READ_SLOW, dwTmemReadSlowItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_SLOW, dwTmemBatchReadSlowItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_WRITE_ERR,  dwTmemWriteErrorItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_READ_ERR, dwTmemReadErrorItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_ERR, dwTmemBatchReadErrorItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_WRITE_REQ,  dwTmemWriteRequestItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_READ_REQ, dwTmemReadRequestItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_REQ, dwTmemBatchReadRequestItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_CELL_REQ, dwTmemBatchReadCellRequestItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_READ_HIT, dwTmemReadHitItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_CELL_HIT, dwTmemBatchReadCellHitItil));

    iRetCode = TMEM_CACHE_OP->Initialize(
            strTmemSvrName,
            dwTmemBid,
            mapTmemItil,
            dwTmemExpireTime,
            (uint16_t)dwTmemReadSlowTime,
            (uint16_t)dwTmemBatchReadSlowTime,
            (uint16_t)dwTmemWriteSlowTime,
            dwTmemBufferSize,
            dwTmemUpdateAddrThreshold,
            bTmemUserNoKey,
            bTmemClosedCache,
            dwTmemReadTimeout,
            dwTmemFailedFreezeTime,
            dwTmemConnectTimeout
    );

    if (0 != iRetCode)
    {
        std::cout << "TMEM_CACHE_OP Initialize() Failed!!" << std::endl;
        return -1;
    }
    else
    {
        std::cout << "TMEM_CACHE_OP Initialize Succ!" << std::endl;
    }
    return 0;
}

int  CCooperatorDao::Initialize(IUserDefineCntl* pCntl)
{
    int32_t iRetCode = 0;
    uint32_t dwLogSwitch=WLOG_OPEN|WLOG_KEY_OPEN|WLOG_ERR_OPEN;

    uint32_t dwCanLogRemote = 0;
    std::string strLogModule="dao_cooperator";
    std::cout<<"File:"<<__FILE__<<" Complie Date: "<<__DATE__<<" "<<__TIME__<<std::endl;

    GetUintConfig(LogSwitch);
    GetStringConfig(LogModule);
    GetUintConfig(CanLogRemote);

    //初始化TMEM
    iRetCode = InitTMEM(pCntl);
    if(iRetCode != 0)
    {
        return iRetCode;
    }
    std::cout<<"InitTmem Initialize OK!"<<std::endl;
    C2C_WW_LOG("InitTmem Initialize OK!");

    // 初始化日志
    if( C2C_WWLOG->QuickInitForAPP2(strLogModule.c_str(),B2B2CWW_LOG_APP_FILE_PATH, dwCanLogRemote, dwLogSwitch)!= 0)
    {
        std::cerr << "C2C_WWLOG->QuickInitForAPP2 Failed" << std::endl;
        return -1;
    }
    C2C_WW_LOG("C2C_WWLOG->QuickInitForAPP2 OK!");

    iRetCode = m_oDBOperator.InitDB(pCntl);
    if( iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "Init DB failed. iRetCode:%d", iRetCode);
        return iRetCode;
    }
    C2C_WW_LOG("InitDB() Success!");

    return 0;
}


/**
 *
 * 更新【新增和修改】合作伙伴基本信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorBaseInfoDdo cooperatorBaseInfoDdo: 合作伙伴基本信息，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::UpdateCooperatorBaseInfo(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo& oCooperatorBaseInfoDdo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oUpdateCooperatorBaseInfoGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                dwSceneId, oCooperatorBaseInfoDdo.GetCooperatorId());

    iRetCode = m_oDBOperator.UpdateCooperatorBaseInfo(rCntlInfo, strMachineKey, strSource,
            dwSceneId, oCooperatorBaseInfoDdo, strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //操作TMEM
    Attr_API2(ITIL_DEL_COOPERATOR_CMEM_CACHE_REQ,1);
    std::stringstream ssKey;
    ssKey << COOPERATOR_CMEM_PREFIX;
    ssKey << oCooperatorBaseInfoDdo.GetCooperatorId();
    //删除TMEM记录
    iRetCode = TMEM_CACHE_OP->DelData(ssKey.str());
    oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->DelData", iRetCode );
    if(iRetCode)
    {
        Attr_API2(ITIL_DEL_COOPERATOR_CMEM_CACHE_ERR,1);
        C2C_WW_LOG_ERR(iRetCode,"%s TMEM_CACHE_OP->DelData,Key:%s",__FUNCTION__,ssKey.str().c_str());
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
                m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                oCooperatorBaseInfoDdo.GetCooperatorId());
    return 0;
}

/**
 *
 * 获取合作伙伴许可证信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param Set licenseType: 许可证类型，为空则为全部许可证列表  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param Vector cooperatorLicenseDdo: 合作伙伴许可证信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::GetCooperatorLicense(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwCooperatorId,
				const std::set<uint8_t >& setLicenseType,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::vector<b2b2c::cooperator::ddo::CCooperatorLicenseDdo >& vecCooperatorLicenseDdo,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetCooperatorLicenseGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%lu", __FUNCTION__,
                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId, ddwCooperatorId);

    //读db,暂时没加cache
    iRetCode = m_oDBOperator.GetCooperatorLicense(rCntlInfo, strMachineKey, strSource,
                        dwSceneId, ddwCooperatorId, setLicenseType, strInReserve, strErrmsg, vecCooperatorLicenseDdo, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%lu ", __FUNCTION__,
                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId, ddwCooperatorId);
    return 0;
}

/**
 *
 * 获取合作伙伴基本信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String inReserve: 请求保留字  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param CooperatorBaseInfoDdo cooperatorBaseInfoDdo: 合作伙伴基本信息 	[out]
 *@param String outReserve: 输出保留字 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::GetCooperatorBaseInfo(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwCooperatorId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo& oCooperatorBaseInfoDdo,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    //uint32_t dwCacheExpireTime = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)? ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetCooperatorBaseInfoGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId);

    //读db
    iRetCode = m_oDBOperator.GetCooperatorBaseInfo(rCntlInfo, strMachineKey, strSource,
                        dwSceneId, ddwCooperatorId, strInReserve, strErrmsg, oCooperatorBaseInfoDdo, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    std::stringstream ssKey;
    ssKey << COOPERATOR_CMEM_PREFIX;
    ssKey << dwCooperatorId;
    iRetCode = TMEM_CACHE_OP->AddData(ssKey.str(),oCooperatorBaseInfoDdo);
    if(0!=iRetCode){
        C2C_WW_LOG_ERR(iRetCode,"%s TMEM_CACHE_OP->AddData,Key:%s",__FUNCTION__,ssKey.str().c_str());
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId, dwCooperatorId);
    return 0;
}

/**
 *
 * 设置合作伙伴密码信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String cooperatorOldPassword: 合作伙伴老密码（三次MD5加密），必填  [in]
 *@param String cooperatorNewPassword: 合作伙伴新密码（三次MD5加密），必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::SetCooperatorPassWd(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwCooperatorId,
				const std::string& strCooperatorOldPassword,
				const std::string& strCooperatorNewPassword,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)?
                                   ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oSetCooperatorPassWdGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu CooperatorOldPassword:%s CooperatorNewPassword:%s",
                    __FUNCTION__, m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                    ddwCooperatorId, strCooperatorOldPassword.c_str(), strCooperatorNewPassword.c_str());

    iRetCode = m_oDBOperator.SetCooperatorPassWd(rCntlInfo, strMachineKey, strSource,
                        dwSceneId, ddwCooperatorId, 0, strCooperatorOldPassword, strCooperatorNewPassword,
                        strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //删cache
    Attr_API2(ITIL_DEL_COOPERATOR_CMEM_CACHE_REQ,1);
    std::stringstream ssKey;
    ssKey << COOPERATOR_KEY_CMEM_PREFIX;
    ssKey << dwCooperatorId;
    iRetCode = TMEM_CACHE_OP->DelData(ssKey.str());
    if(0!=iRetCode){
        Attr_API2(ITIL_DEL_COOPERATOR_CMEM_CACHE_ERR,1);
        C2C_WW_LOG_ERR(iRetCode,"%s TMEM_CACHE_OP->DelData,Key:%s",__FUNCTION__,ssKey.str().c_str());
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu CooperatorOldPassword:%s CooperatorNewPassword:%s",
                __FUNCTION__, m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                ddwCooperatorId, strCooperatorOldPassword.c_str(), strCooperatorNewPassword.c_str());
    return 0;
}

/**
 *
 * 检查合作伙伴密码信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String cooperatorPassword: 合作伙伴密码（三次MD5加密），必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::CheckCooperatorPassWd(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwCooperatorId,
				const std::string& strCooperatorPassword,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oCheckCooperatorPassWdGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu", __FUNCTION__,
                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId, ddwCooperatorId);

    iRetCode = m_oDBOperator.CheckCooperatorPassWd(rCntlInfo, strMachineKey, strSource,
            dwSceneId, ddwCooperatorId, strCooperatorPassword, strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu", __FUNCTION__,
                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId, ddwCooperatorId);
    return 0;
}

/**
 *
 * 更新【新增和修改】合作伙伴许可证信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorLicenseDdo cooperatorLicenseDdo: 合作伙伴许可证信息，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::UpdateCooperatorLicense(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const b2b2c::cooperator::ddo::CCooperatorLicenseDdo& oCooperatorLicenseDdo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oUpdateCooperatorLicenseGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
                m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                oCooperatorLicenseDdo.GetCooperatorId());

    iRetCode = m_oDBOperator.UpdateCooperatorLicense(rCntlInfo, strMachineKey, strSource,
            dwSceneId, oCooperatorLicenseDdo, strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
            m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId,
            oCooperatorLicenseDdo.GetCooperatorId());
    return 0;
}

/**
 *
 * 获取合作伙伴数据加密Key
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String sCooperatorKey: 合作伙伴数据加密Key，长度32bytes；生成规则：合作伙伴当前密码三次MD5加密后的值   [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::GetCooperatorKey(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwCooperatorId,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::string& strSCooperatorKey,
                std::string& strOutReserve
    )
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetCooperatorKeyGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu", __FUNCTION__,
                m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId, ddwCooperatorId);

    iRetCode = m_oDBOperator.GetCooperatorKey(rCntlInfo, strMachineKey, strSource,
            dwSceneId, ddwCooperatorId, strInReserve, strErrmsg, strSCooperatorKey, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu", __FUNCTION__,
            m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId,ddwCooperatorId);
    return 0;
}

/**
 *
 * 支付物流系统设置卖家的次日达，货到付款等属性位接口
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t option: 选项,暂未用  [in]
 *@param CooperatorProDdo cooperatorProDdo: 合作伙伴属性位设置，包括合作伙伴ID、设置和取消属性值设置的参数（设置和取消的属性位不能冲突），必填  [in]
 *@param String inReserve: 请求保留字  [in]
 *@param String errmsg: 错误信息    [out]
 *@param CooperatorBaseInfoDdo cooperatorBaseInfoDdo: 合作伙伴属性    [out]
 *@param String outReserve: 输出保留字   [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::SetCooperatorPro(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwOption,
                const b2b2c::cooperator::ddo::CCooperatorProDdo& oCooperatorProDdo,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::string& strOutReserve
    )
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oLogisticsSetCooperatorPro);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                dwSceneId, oCooperatorProDdo.GetCooperatorId());

    iRetCode = m_oDBOperator.SetCooperatorPro(rCntlInfo, strMachineKey, strSource,
            dwSceneId, 0, oCooperatorProDdo,  strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //操作TMEM
    Attr_API2(ITIL_DEL_COOPERATOR_CMEM_CACHE_REQ,1);
    std::stringstream ssKey;
    ssKey << COOPERATOR_CMEM_PREFIX;
    ssKey << oCooperatorProDdo.GetCooperatorId();
    //删除TMEM记录
    iRetCode = TMEM_CACHE_OP->DelData(ssKey.str());
    oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->DelData", iRetCode );
    if(iRetCode)
    {
        Attr_API2(ITIL_DEL_COOPERATOR_CMEM_CACHE_ERR,1);
        C2C_WW_LOG_ERR(iRetCode,"%s TMEM_CACHE_OP->DelData,Key:%s",__FUNCTION__,ssKey.str().c_str());
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
                m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId,
                oCooperatorProDdo.GetCooperatorId());
    return 0;
}

/**
 *
 * 从管理后台等其他业务同步过来的设置合作伙伴属性位等信息的接口
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t option: 选项,暂未用  [in]
 *@param CooperatorSetDdo cooperatorSetDdo: 合作伙伴属性位设置，包括合作伙伴ID、设置和取消属性值设置的参数（设置和取消的属性位不能冲突）等，必填  [in]
 *@param String inReserve: 请求保留字  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String outReserve: 输出保留字   [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::SetCooperatorInfo(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwOption,
                const b2b2c::cooperator::ddo::CCooperatorSetDdo& oCooperatorSetDdo,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::string& strOutReserve
    )
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;
    uint32_t dwCooperatorId = 0;
    if(oCooperatorSetDdo.IsCooperatorProDdoSet()){
        dwCooperatorId = oCooperatorSetDdo.GetCooperatorProDdo().GetCooperatorId();
    }
    if(oCooperatorSetDdo.IsCooperatorSubProDdoSet()){
        dwCooperatorId = oCooperatorSetDdo.GetCooperatorSubProDdo().GetCooperatorId();
    }

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oSetCooperatorInfo);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
                __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                dwSceneId);

    iRetCode = m_oDBOperator.SetCooperatorInfo(rCntlInfo, strMachineKey, strSource,
            dwSceneId, 0, oCooperatorSetDdo,  strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //操作TMEM
    Attr_API2(ITIL_DEL_COOPERATOR_CMEM_CACHE_REQ,1);
    std::stringstream ssKey;
    ssKey << COOPERATOR_CMEM_PREFIX;
    ssKey << dwCooperatorId;
    //删除TMEM记录
    iRetCode = TMEM_CACHE_OP->DelData(ssKey.str());
    oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->DelData", iRetCode );
    if(iRetCode)
    {
        Attr_API2(ITIL_DEL_COOPERATOR_CMEM_CACHE_ERR,1);
        C2C_WW_LOG_ERR(iRetCode,"%s TMEM_CACHE_OP->DelData,Key:%s",__FUNCTION__,ssKey.str().c_str());
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__,
                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(), dwSceneId);
    return 0;
}


/**
 *
 * 获取价格告警模版列表
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param Vector CooperatorMonitorModelDdo: 告警模版列表 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::GetCooperatorMonitorModelList(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwCooperatorId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::vector<b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo >& vecCooperatorMonitorModelDdo,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;//?int32

	m_dwOperatorUin=rCntlInfo.getOperatorUin();
	m_dwSceneId=dwSceneId;
	m_strMachineKey=strMachineKey;
	m_strSource=strSource;

	C2C_WW_SIM_LOG_PL_HEAD();
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetMonitorModelListGroup);
	C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId, dwCooperatorId);

	//读db
	iRetCode = m_oDBOperator.GetCooperatorMonitorModelList(rCntlInfo, strMachineKey, strSource,
						dwSceneId, dwCooperatorId, strInReserve, strErrmsg, vecCooperatorMonitorModelDdo, strOutReserve);
	//性能日志
	oWTimeElf.AddTimeMark( "DBOperator->GetCooperatorMonitorModelList", iRetCode);

	if(0!=iRetCode)
	{
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	std::stringstream ssKey;
	ssKey << COOPERATOR_MONITOR_CMEM_PREFIX;
	ssKey << dwCooperatorId;
	iRetCode = TMEM_CACHE_OP->AddSimpleData(ssKey.str(),vecCooperatorMonitorModelDdo);

	//性能日志
	oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->AddSimpleData", iRetCode);

	if(0!=iRetCode){
		C2C_WW_LOG_ERR(iRetCode,"%s TMEM_CACHE_OP->AddSimpleData,Key:%s",__FUNCTION__,ssKey.str().c_str());
	}

	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId, dwCooperatorId);

	iRetCode=0;
	return iRetCode;
}

/**
 *
 * 新增或者更新告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorMonitorModelDdo CooperatorMonitorModelDdo: 告警模版，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::UpdateCooperatorMonitorModel(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo& oCooperatorMonitorModelDdo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;//?int32

	m_dwOperatorUin=rCntlInfo.getOperatorUin();
	m_dwSceneId=dwSceneId;
	m_strMachineKey=strMachineKey;
	m_strSource=strSource;

	C2C_WW_SIM_LOG_PL_HEAD();
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oUpdateMonitorModelGroup);
	C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId, oCooperatorMonitorModelDdo.GetCooperatorId());

	//DB操作
	iRetCode = m_oDBOperator.UpdateCooperatorMonitorModel(rCntlInfo, strMachineKey, strSource,
						dwSceneId, oCooperatorMonitorModelDdo, strInReserve, strErrmsg, strOutReserve);

	//性能日志
	oWTimeElf.AddTimeMark( "DBOperator->UpdateCooperatorMonitorModel", iRetCode);

	if(0!=iRetCode)
	{
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	//删cache
	//删不掉的话会有脏数据，所以要itil上报一下
	Attr_API2(ITIL_MINITOR_DEL_CMEM_CACHE_REQ,1);//这里没搞明白
	std::stringstream ssKey;
	ssKey << COOPERATOR_MONITOR_CMEM_PREFIX;
	ssKey << oCooperatorMonitorModelDdo.GetCooperatorId();
	iRetCode = TMEM_CACHE_OP->DelData(ssKey.str());

	//性能日志
	oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->DelData", iRetCode);

	if(0!=iRetCode){
		Attr_API2(ITIL_MINITOR_DEL_CMEM_CACHE_ERR,1);
		C2C_WW_LOG_ERR(iRetCode,"%s TMEM_CACHE_OP->DelData,Key:%s",__FUNCTION__,ssKey.str().c_str());
	}

	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId, oCooperatorMonitorModelDdo.GetCooperatorId());

	iRetCode=0;
	return iRetCode;
}

/**
 *
 * 删除告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param uint32_t modelId: 模版ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::DeleteCooperatorMonitorModel(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwCooperatorId,
				uint32_t dwModelId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;//?int32

	m_dwOperatorUin=rCntlInfo.getOperatorUin();
	m_dwSceneId=dwSceneId;
	m_strMachineKey=strMachineKey;
	m_strSource=strSource;

	C2C_WW_SIM_LOG_PL_HEAD();
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oDeleteMonitorModelGroup);
	C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId, dwCooperatorId);

	//DB操作
	iRetCode = m_oDBOperator.DeleteCooperatorMonitorModel(rCntlInfo, strMachineKey, strSource,
						dwSceneId, dwCooperatorId,dwModelId, strInReserve, strErrmsg, strOutReserve);

	//性能日志
	oWTimeElf.AddTimeMark( "DBOperator->DeleteCooperatorMonitorModel", iRetCode);

	if(0!=iRetCode)
	{
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	//删cache
	//删不掉的话会有脏数据，所以要itil上报一下
	Attr_API2(ITIL_MINITOR_DEL_CMEM_CACHE_REQ,1);//这里没搞明白
	std::stringstream ssKey;
	ssKey << COOPERATOR_MONITOR_CMEM_PREFIX;
	ssKey << dwCooperatorId;
	iRetCode = TMEM_CACHE_OP->DelData(ssKey.str());

	//性能日志
	oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->DelData", iRetCode);

	if(0!=iRetCode){
		Attr_API2(ITIL_MINITOR_DEL_CMEM_CACHE_ERR,1);
		C2C_WW_LOG_ERR(iRetCode,"%s TMEM_CACHE_OP->DelData,Key:%s",__FUNCTION__,ssKey.str().c_str());
	}

	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId, dwCooperatorId);

	iRetCode=0;
	return iRetCode;
}

/**
 *
 * 通过模版ID获取告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param uint32_t modelId: 模版ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param CooperatorMonitorModelDdo CooperatorMonitorModelDdo: 告警模版 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorDao::GetCooperatorMonitorModel(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwCooperatorId,
				uint32_t dwModelId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo& oCooperatorMonitorModelDdo,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;//?int32

	m_dwOperatorUin=rCntlInfo.getOperatorUin();
	m_dwSceneId=dwSceneId;
	m_strMachineKey=strMachineKey;
	m_strSource=strSource;

	C2C_WW_SIM_LOG_PL_HEAD();
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetMonitorModelGroup);
	C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId, dwCooperatorId);

	//读db
	iRetCode = m_oDBOperator.GetCooperatorMonitorModel(rCntlInfo, strMachineKey, strSource,
						dwSceneId, dwCooperatorId, dwModelId, strInReserve, strErrmsg, oCooperatorMonitorModelDdo, strOutReserve);
	//性能日志
	oWTimeElf.AddTimeMark( "DBOperator->GetCooperatorMonitorModel", iRetCode);

	if(0!=iRetCode)
	{
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u", __FUNCTION__,
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId, dwCooperatorId);

	iRetCode=0;
	return iRetCode;
}

